package it.fuesi.synoutils.activities;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

import it.fuesi.synoutils.R;
import it.fuesi.synoutils.model.download.DownloadStationClientParameters;
import it.fuesi.synoutils.model.download.DownloadStationConfig;
import it.fuesi.synoutils.services.tasks.download.DownloadConfigTask;

public class DownloadStationSettingsActivity extends Activity {


    private DownloadStationConfig config;
    private TextView mSetting1;
    private TextView mSetting2;
    private TextView mSetting3;
    private TextView mSetting4;
    private TextView mSetting5;
    private TextView mSetting6;
    private TextView mSetting7;
    private TextView mSetting8;
    private TextView mSetting9;
    private TextView mSetting10;
    private TextView mSetting11;


    public void setConfig(DownloadStationConfig config){
        this.config = config;
        bindValues();
    }

    private void bindValues(){
        mSetting1.setText(""+config.getBt_max_download());
        mSetting2.setText(""+config.getBt_max_upload());
        mSetting3.setText(""+config.isEmule_enabled());
        mSetting4.setText(""+config.getEmule_max_download());
        mSetting5.setText(""+config.getEmule_max_upload());
        mSetting6.setText(""+config.getFtp_max_download());
        mSetting7.setText(""+config.getHttp_max_download());
        mSetting8.setText(""+config.getNzb_max_download());
        mSetting9.setText(""+config.isUnzip_service_enabled());
        mSetting10.setText(config.getDefault_destination());
        mSetting11.setText(config.getEmule_default_destination());
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_download_station_settings);

        mSetting1 = (TextView)findViewById(R.id.download_setting_bt_max_download);
        mSetting2 = (TextView)findViewById(R.id.download_setting_bt_max_upload);
        mSetting3 = (TextView)findViewById(R.id.download_setting_emule_enabled);
        mSetting4 = (TextView)findViewById(R.id.download_setting_emule_max_download);
        mSetting5 = (TextView)findViewById(R.id.download_setting_emule_max_upload);
        mSetting6 = (TextView)findViewById(R.id.download_setting_ftp_max_download);
        mSetting7 = (TextView)findViewById(R.id.download_setting_http_max_download);
        mSetting8 = (TextView)findViewById(R.id.download_setting_nzb_max_download);
        mSetting9 = (TextView)findViewById(R.id.download_setting_unzip_service_enabled);
        mSetting10 = (TextView)findViewById(R.id.download_setting_default_destination);
        mSetting11 = (TextView)findViewById(R.id.download_setting_emule_default_destination);

    }


    @Override
    protected void onResume() {
        super.onResume();

        fetch();
    }

    private void fetch(){
        DownloadStationClientParameters params = new DownloadStationClientParameters();

        new DownloadConfigTask(this).execute(params);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.download_station_settings, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
